package com.jastar.android.game.richman.logic.bean;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.jastar.android.game.richman.logic.card.Card;
import com.jastar.android.game.richman.logic.enums.LandType;

import java.util.ArrayList;
import java.util.List;

public class Player {

    private String name;
    private int position;
    private int money;
    private int color;
    private int icon;
    private List<Card> cards;
    private int nextRoll = 0;

    private Bitmap bitmap;
    private Bitmap thumbnailBitmap;

    public Player(String name, int money, int color, int icon) {
        this.name = name;
        this.money = money;
        this.color = color;
        this.icon = icon;
    }

    public void loadBitmap(Resources resources, int h) {
        this.bitmap = BitmapFactory.decodeResource(resources, icon);
        int w = h * bitmap.getWidth() / bitmap.getHeight();
        this.thumbnailBitmap = Bitmap.createScaledBitmap(bitmap, w, h, false);
    }

    public void buy(Cell cell, LandType landType) {
        this.pay(cell.getPrice());
        cell.setLandType(landType);
        cell.setMaxLevel(landType.getMaxLevel());
        cell.setOwner(this);
    }

    public void payUntilZero(int num) {
        money -= Math.min(money, num);
    }

    public void pay(int num) {
        money -= num;
    }

    public void receive(int num) {
        money += num;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public String getName() {
        return name;
    }

    public int getPosition() {
        return position;
    }

    public int getMoney() {
        return money;
    }

    public int getColor() {
        return color;
    }

    public int getIcon() {
        return icon;
    }

    public Bitmap getBitmap() {
        return bitmap;
    }

    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public Bitmap getThumbnailBitmap() {
        return thumbnailBitmap;
    }

    public void setThumbnailBitmap(Bitmap thumbnailBitmap) {
        this.thumbnailBitmap = thumbnailBitmap;
    }

    public void addCard(Card card) {
        getCards().add(card);
    }

    public List<Card> getCards() {
        if (null == cards) cards = new ArrayList<>();
        return this.cards;
    }

    public int getNextRoll() {
        return nextRoll;
    }

    public void setNextRoll(int nextRoll) {
        this.nextRoll = nextRoll;
    }

}